package com.huikeportal.controller;

import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import net.sf.json.JSONArray;
import jxl.write.Alignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huikeportal.controller.common.ExcelCreate;
import com.huikeportal.controller.common.Lang;
import com.huikeportal.controller.common.MessageManager;
import com.huikeportal.controller.common.Tools;
import com.huikeportal.model.ChangeGcParam;
import com.huikeportal.model.Language;
import com.huikeportal.model.RegionModel;
import com.huikeportal.model.ReportGraphData;
import com.huikeportal.model.SiteAllInfo;
import com.huikeportal.model.SiteCommon;
import com.huikeportal.model.SiteIndex;
import com.huikeportal.model.SiteSimpleInfo;
import com.huikeportal.model.SquareChange;
import com.huikeportal.model.UserInfo;
import com.huikeportal.model.WordBook;
import com.huikeportal.model.common.CellVo;
import com.huikeportal.model.common.ExcelVo;
import com.huikeportal.model.common.IndexPermission;
import com.huikeportal.model.common.PageDataVo;
import com.huikeportal.model.common.SheetVo;
import com.huikeportal.model.common.SqlParameter;
import com.huikeportal.service.CommonService;
import com.huikeportal.service.FootfallGlobalService;
import com.huikeportal.service.LoginService;
import com.huikeportal.service.OverViewService;
import com.huikeportal.service.SelectSiteService;

@Controller
public class RegionViewController {

	@Autowired
	private HttpSession session;

	@Autowired
	private LoginService loginService;

	@Autowired
	private OverViewService overViewService;

	@Autowired
	private FootfallGlobalService footfallGlobalService;

	@Autowired
	private SelectSiteService selectSiteService;

	@Autowired
	private CommonService commonService;

	@RequestMapping("/regionView")
	public String regionView(String siteId, ModelMap model) throws Exception {
		RegionModel regionModel = new RegionModel();
		if (siteId != null && !"".equals(siteId)) {
			regionModel.setGcSiteId(siteId);
		}
		String sysLang = session.getAttribute("sysLang").toString();
		Language lang = Lang.getInfo(sysLang);
		model.addAttribute("lang", lang);
		UserInfo userInfo = (UserInfo) session.getAttribute("sessionUserName");
		String menuHtml = loginService.getMenuHtml(userInfo, "regionView");
		model.addAttribute("menuHtml", menuHtml);// 左侧菜单html
		// 获取用户信息
		userInfo = loginService.getUserInfo(userInfo);
		// 获取用户根据店铺反查的广场权限
		List<SiteAllInfo> dpGcList = loginService.getDpGcSiteList(userInfo);
		// 获取用户单独广场权限
		List<SiteAllInfo> gcList = loginService.getGcSiteList(userInfo);
		// 获取用户单独店铺权限
		List<SiteAllInfo> jinDpList = loginService.getJinDpSiteList(userInfo);
		// 如果没有权限
		if (dpGcList.size() == 0) {
			return "noPermission";
		}
		// 如果是第一次进来，广场为空
		if (regionModel.getGcSiteId() == null
				|| "".equals(regionModel.getGcSiteId())) {
			// 从session中获取上一次选中的广场，如果没有，从历史表中获取上一次选中的广场，如果没有，则获取第一家广场，并存入历史表，存入session
			if (session.getAttribute("userSiteSession") != null
					&& !"".equals(session.getAttribute("userSiteSession"))) {
				regionModel.setGcSiteId(session.getAttribute("userSiteSession")
						.toString());
			}
			// 如果session中不存在
			else {
				// 从历史表中获取上一次选中的广场
				String lastSiteId = overViewService.getLastSiteId(userInfo,
						"footfallWhole", sysLang);
				// 如果存在
				if (!"".equals(lastSiteId)) {
					// 判断当前场所权限是否存在

					regionModel.setGcSiteId(lastSiteId);
					// 存入session
					session.setAttribute("userSiteSession", lastSiteId);
				}
				// 存入历史表，存入session
				else {
					// 获取第一家广场
					String gcSiteId = "";
					// 如果是从广场权限中选中的广场
					if (gcList.size() != 0) {
						gcSiteId = gcList.get(0).getSiteid();
					}
					// 如果是通过店铺反查选中的广场,sql中需加入店铺范围
					else {
						gcSiteId = dpGcList.get(0).getSiteid();
					}
					regionModel.setGcSiteId(gcSiteId);
					// 存入历史表
					overViewService.insertLastSiteId(userInfo, "footfallWhole",
							gcSiteId, sysLang);
					// 存入session
					session.setAttribute("userSiteSession", gcSiteId);
				}
			}
		} else {
			// 更新历史表
			overViewService.updateLastSiteId(userInfo, "footfallWhole",
					regionModel.getGcSiteId(), sysLang);
			// 更新session
			session.setAttribute("userSiteSession", regionModel.getGcSiteId());
		}
		/** 如果广场不是有权限的广场，则加入店铺过滤器 **/
		if (!Tools.isHaveGcPer(gcList, regionModel.getGcSiteId())) {
			regionModel.setDpString(Tools.pinjieId(jinDpList));
		}
		/** 更换广场初始化 **/
		// 初始化默认广场信息
		SiteCommon siteCommon = selectSiteService.querySiteInfo(regionModel
				.getGcSiteId());
		model.addAttribute("siteCommon", siteCommon);
		// 更换广场div初始化数据
		ChangeGcParam changeGcParam = new ChangeGcParam();
		changeGcParam.setSelectType("0");// 单选广场
		changeGcParam.setGcString(siteCommon.getSiteId());// 已经选择的广场id
		List<SiteAllInfo> yuanGcList = loginService.getGcSiteList(userInfo);
		SquareChange squareChange = selectSiteService.squareChangeLoad(
				changeGcParam, dpGcList, yuanGcList);// 获取初始化更换广场信息
		model.addAttribute("squareChange", squareChange);
		model.addAttribute("selectType", changeGcParam.getSelectType());
		model.addAttribute("backPage", "regionView");
		/** 更换广场初始化 **/
		// 拼接下拉框
		List<SiteAllInfo> leftList = new ArrayList<SiteAllInfo>();
		List<SiteSimpleInfo> rightGcList = new ArrayList<SiteSimpleInfo>();
		List<SiteSimpleInfo> rightQyList = new ArrayList<SiteSimpleInfo>();
		List<SiteSimpleInfo> rightLcList = new ArrayList<SiteSimpleInfo>();
		List<SiteSimpleInfo> rightDpList = new ArrayList<SiteSimpleInfo>();
		SiteAllInfo site = new SiteAllInfo();
		List<SiteSimpleInfo> gcQyList = overViewService.getComboResult(
				regionModel, "0", userInfo);
		List<SiteSimpleInfo> qyQyList = overViewService.getComboResult(
				regionModel, "1", userInfo);
		List<SiteSimpleInfo> lcQyList = overViewService.getComboResult(
				regionModel, "2", userInfo);
		List<SiteSimpleInfo> dpQyList = overViewService.getComboResult(
				regionModel, "3", userInfo);
		if (gcQyList.size() != 0) {
			site = new SiteAllInfo();
			site.setSiteid("300");
			site.setSitename(lang.getSquare());
			leftList.add(site);
			rightGcList = gcQyList;
		}
		if (qyQyList.size() != 0) {
			site = new SiteAllInfo();
			site.setSiteid("400");
			site.setSitename(lang.getDomain());
			leftList.add(site);
			rightQyList = qyQyList;
		}
		if (lcQyList.size() != 0) {
			site = new SiteAllInfo();
			site.setSiteid("500");
			site.setSitename(lang.getFloor());
			leftList.add(site);
			rightLcList = lcQyList;
		}
		if (dpQyList.size() != 0) {
			site = new SiteAllInfo();
			site.setSiteid("600");
			site.setSitename(lang.getStore());
			leftList.add(site);
			rightDpList = dpQyList;
		}
		model.addAttribute("leftList", leftList);
		model.addAttribute("rightGcList", JSONArray.fromObject(rightGcList)
				.toString());
		model.addAttribute("rightQyList", JSONArray.fromObject(rightQyList)
				.toString());
		model.addAttribute("rightLcList", JSONArray.fromObject(rightLcList)
				.toString());
		model.addAttribute("rightDpList", JSONArray.fromObject(rightDpList)
				.toString());
		// 获取用户指标权限
		List<String> indexList = footfallGlobalService.getUserIndex(userInfo);
		indexList = commonService.getIndexList(indexList, "1_5", "400", "1");
		IndexPermission index = Tools.initIndex(indexList, sysLang);
		model.addAttribute("indexList", index);// 用于标题栏动态显示
		model.addAttribute("index", JSONArray.fromObject(index).toString());
		// 获取用户按钮权限
		// 查询当前页面id
		SqlParameter sql = new SqlParameter();
		sql.setSysLang(sysLang);
		sql.setString("regionView");
		Integer menuId = selectSiteService.getMenuId(sql);
		// 获取用户权限按钮信息
		List<WordBook> buttonList = loginService.getUserButtonList(sysLang,
				userInfo.getUserId(), menuId);
		String isHaveExport = "0";
		for (int i = 0; i < buttonList.size(); i++) {
			if ("8".equals(buttonList.get(i).getDicCode())) {
				isHaveExport = "1";
				break;
			}
		}
		model.addAttribute("isHaveExport", isHaveExport);

		/********* 判断场所是否拥有视频、wifi等指标 2016年2月17日16:34:40 ***********/
		String kllSum = MessageManager.getMsg("kllSum");
		if ("on".equals(kllSum)) {
			boolean shipinFlag = commonService.isGcHaveIndex(regionModel
					.getGcSiteId(), null, null, "0", "0");
			boolean wifiFlag = commonService.isGcHaveIndex(regionModel
					.getGcSiteId(), null, null, "0", "1");
			// 如果没有视频客流，返回到新页面
			if (leftList.size() != 0 && !shipinFlag) {
				// 如果有wifi探针
				if (wifiFlag) {
					model.addAttribute("isHaveWifi", "0");
				} else {
					model.addAttribute("isHaveWifi", "1");
				}
				return "areaNewview";
			}
		}
		/********* 判断场所是否拥有视频、wifi等指标 ***********/
		return "areaOverview";
	}

	/**
	 * 根据场所id查询场所指标
	 * 
	 * @param qyList
	 * @param regionModel
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	private List<SiteIndex> pinjieIndex(List qyList, RegionModel regionModel,
			UserInfo userInfo) throws Exception {
		// 区域客流合计2016年2月19日11:28:17
		String lowSiteId = "";
		String topSiteId = "";
		if (regionModel.getGcSiteId() != null
				&& !"".equals(regionModel.getGcSiteId())) {
			topSiteId = regionModel.getGcSiteId();
		} else if (regionModel.getQySiteId() != null
				&& !"".equals(regionModel.getQySiteId())) {
			lowSiteId = regionModel.getQySiteId();
			topSiteId = selectSiteService.querySiteInfo(lowSiteId)
					.getParent300();
		} else if (regionModel.getLcSiteId() != null
				&& !"".equals(regionModel.getLcSiteId())) {
			lowSiteId = regionModel.getLcSiteId();
			topSiteId = selectSiteService.querySiteInfo(lowSiteId)
					.getParent300();
		} else if (regionModel.getDpSiteId() != null
				&& !"".equals(regionModel.getDpSiteId())) {
			lowSiteId = regionModel.getDpSiteId();
			topSiteId = selectSiteService.querySiteInfo(lowSiteId)
					.getParent300();
		}
		boolean shipinFlag = commonService.isGcHaveIndex(topSiteId, null, null,
				"0", "0");
		String kllSum = MessageManager.getMsg("kllSum");
		List<SiteIndex> siteIndexList = new ArrayList<SiteIndex>();
		// 循环区域列表，计算每一个指标
		for (int i = 0; i < qyList.size(); i++) {
			SiteAllInfo qySite = (SiteAllInfo) qyList.get(i);
			SiteIndex siteIndex = new SiteIndex();
			siteIndex.setSiteId(qySite.getSiteid());
			siteIndex.setSiteName(qySite.getSitename());
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("timeType", regionModel.getTimeType());// 设置当天最近7、14天等
			map.put("timeType_table", regionModel.getDateType());// 设置日周月年
			map.put("startDate", regionModel.getStartDate());// 设置自己选中的开始日期
			map.put("endDate", regionModel.getEndDate());// 设置自己选中的结束日期
			map.put("siteId", qySite.getSiteid());// 设置场所id
			map.put("userInfo", userInfo);// 设置当前用户
			List<ReportGraphData> dataList = footfallGlobalService
					.getGraphData(map);
			siteIndex = Tools.mathIndex(dataList, siteIndex);

			// 如果没有该项目下区域没有视频客流，计算旗下店铺客流总和作为新指标-区域客流
			if (!shipinFlag&&"on".equals(kllSum)) {
				RegionModel region = new RegionModel();
				region.setQySiteId(((SiteAllInfo) qyList.get(i)).getSiteid());
				// 查询区域下的所有店铺
				List<SiteAllInfo> lowDpList = selectSiteService
						.getTwiceDp(region);
				Long qyInNum = 0L;
				for (int j = 0; j < lowDpList.size(); j++) {
					HashMap<String, Object> map1 = new HashMap<String, Object>();
					map1.put("timeType", regionModel.getTimeType());// 设置当天最近7、14天等
					map1.put("timeType_table", regionModel.getDateType());// 设置日周月年
					map1.put("startDate", regionModel.getStartDate());// 设置自己选中的开始日期
					map1.put("endDate", regionModel.getEndDate());// 设置自己选中的结束日期
					map1.put("siteId", lowDpList.get(j).getSiteid());// 设置场所id
					map1.put("userInfo", userInfo);// 设置当前用户
					List<ReportGraphData> dataList1 = footfallGlobalService
							.getGraphData(map1);
					for (int k = 0; k < dataList1.size(); k++) {
						qyInNum += dataList1.get(k).getInnum();
					}
				}
				siteIndex.setIndex0_0(revert0(qyInNum.toString()));
			}

			siteIndexList.add(siteIndex);
		}
		return siteIndexList;
	}

	// 取整数
	private static String revert0(String string) {
		BigDecimal b = new BigDecimal(string);
		DecimalFormat d1 = new DecimalFormat("#,##0");
		return d1.format(b);
	}

	/**
	 * ajax查询区域概览
	 * 
	 * @param siteType
	 * @param siteId
	 * @param qyName
	 * @param qyDate
	 * @param qyTime
	 * @param startDate
	 * @param endDate
	 * @param currentPage
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/getQyView")
	@ResponseBody
	public Map<String, Object> getQyView(String siteType, String siteId,
			String qyName, String qyDate, String qyTime, String startDate,
			String endDate, String currentPage) throws Exception {
		UserInfo userInfo = (UserInfo) session.getAttribute("sessionUserName");
		RegionModel regionModel = initRegion(siteType, siteId, qyName, qyDate,
				qyTime, startDate, endDate);
		PageDataVo pageDataVo = new PageDataVo();
		// 根据广场查询首页区域(分页查询)
		if (currentPage == null || "".equals(currentPage)) {
			pageDataVo.setCurrentPage(1);
		} else {
			pageDataVo.setCurrentPage(Integer.parseInt(currentPage));
		}
		// 获取每页显示条数
		pageDataVo.setPageSize(Integer.parseInt(MessageManager
				.getMsg("viewPageSize")));
		// 设置开始行数
		pageDataVo.setStartRow((pageDataVo.getCurrentPage() - 1)
				* pageDataVo.getPageSize());
		pageDataVo.setSearchParameter(regionModel);
		// 分页查询区域
		pageDataVo = overViewService.getQyList(pageDataVo);
		// 根据区域查询指标信息
		List<SiteIndex> indexList = pinjieIndex(pageDataVo.getPageResult(),
				regionModel, userInfo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("indexList", indexList);
		/*** 动态获取指标，2015年12月4日15:47:12 **/
		// 获取用户指标权限
		String sysLang = session.getAttribute("sysLang").toString();
		userInfo = loginService.getUserInfo(userInfo);
		List<String> indexL = footfallGlobalService.getUserIndex(userInfo);
		// 1_5代表区域概览模块，400代表区域
		String dateType = "";
		// 时
		if ("hour".equals(qyDate)) {
			dateType = "1";
		}
		// 日
		else if ("day".equals(qyDate)) {
			dateType = "2";
		}
		// 周
		else if ("week".equals(qyDate)) {
			dateType = "3";
		}
		// 月
		else if ("month".equals(qyDate)) {
			dateType = "4";
		}
		// 年
		else if ("year".equals(qyDate)) {
			dateType = "5";
		}
		indexL = commonService.getIndexList(indexL, "1_5", "400", dateType);
		IndexPermission index = Tools.initIndex(indexL, sysLang);
		map.put("index", index);
		/*** 动态获取指标，2015年12月4日15:47:12 end **/
		// 设置分页参数
		map.put("currentPage", pageDataVo.getCurrentPage());
		map.put("maxPage", pageDataVo.getMaxPage());
		return map;
	}

	/**
	 * 初始化查询区域参数信息
	 * 
	 * @param siteType
	 * @param siteId
	 * @param qyName
	 * @param qyDate
	 * @param qyTime
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws Exception
	 */
	private RegionModel initRegion(String siteType, String siteId,
			String qyName, String qyDate, String qyTime, String startDate,
			String endDate) throws Exception {
		RegionModel regionModel = new RegionModel();
		if ("300".equals(siteType)) {
			regionModel.setGcSiteId(siteId);
		} else if ("400".equals(siteType)) {
			regionModel.setQySiteId(siteId);
		} else if ("500".equals(siteType)) {
			regionModel.setLcSiteId(siteId);
		} else if ("600".equals(siteType)) {
			regionModel.setDpSiteId(siteId);
		}
		if (qyName != null && !"".equals(qyName)) {
			regionModel.setQySiteName(URLDecoder.decode(qyName, "UTF-8"));
		}
		regionModel.setDateType(qyDate);
		regionModel.setTimeType(qyTime);
		if (startDate != null && !"".equals(startDate)) {
			regionModel.setStartDate(startDate);
		}
		if (endDate != null && !"".equals(endDate)) {
			regionModel.setEndDate(endDate);
		}
		return regionModel;
	}

	/**
	 * 概览页面导出
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/gailanExport")
	@ResponseBody
	public HashMap<String, Object> exportRegionExcel(
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String table = request.getParameter("table").toString();
		table = java.net.URLDecoder.decode(table, "UTF-8");
		String fileName = request.getParameter("fileName").toString();
		fileName = java.net.URLDecoder.decode(fileName, "UTF-8");
		String character = request.getParameter("character").toString();
		character = java.net.URLDecoder.decode(character, "UTF-8");
		String describe = request.getParameter("describe").toString();
		describe = java.net.URLDecoder.decode(describe, "UTF-8");

		// 修改样式
		WritableFont font1 = new WritableFont(WritableFont.createFont("宋体"),
				10, WritableFont.BOLD);
		WritableFont font2 = new WritableFont(WritableFont.createFont("宋体"),
				10, WritableFont.NO_BOLD);
		WritableFont font3 = new WritableFont(WritableFont.createFont("宋体"),
				10, WritableFont.NO_BOLD);
		WritableFont font4 = new WritableFont(WritableFont.createFont("宋体"),
				10, WritableFont.NO_BOLD);
		WritableCellFormat wcf1 = new WritableCellFormat(font1);
		WritableCellFormat wcf2 = new WritableCellFormat(font2);
		WritableCellFormat wcf3 = new WritableCellFormat(font3);
		WritableCellFormat wcf4 = new WritableCellFormat(font4);
		wcf1.setAlignment(Alignment.CENTRE); // 平行居中
		wcf2.setAlignment(Alignment.CENTRE); // 平行居中
		wcf3.setAlignment(Alignment.RIGHT); // 平行居右
		wcf4.setAlignment(Alignment.LEFT); // 平行居右

		String[] strs = new String[8];
		// 截取数据说明文字
		describe = describe.replaceAll("</div><div>", ";");
		describe = describe.replace("</div><div id=\"zhibiaomingcheng\">", ";");
		describe = describe.replace("amp;", "");
		describe = describe.substring(5, describe.length() - 6);
		strs[0] = describe;
		ArrayList<String[]> tables = changeTableToList(table);
		ArrayList<String[]> tablesExcle = new ArrayList<String[]>();
		for (String[] row : tables) {
			List<String> list = new ArrayList<String>();
			for (int i = 0; i < row.length; i++) {
				list.add(row[i]);
			}
			list.remove(0);
			list.remove(1);
			String[] newStr = list.toArray(new String[1]); // 返回一个包含所有对象的指定类型的数组
			tablesExcle.add(newStr);
		}
		tablesExcle.add(0, strs);
		// 新建excel对象
		ExcelVo excelVo = new ExcelVo();
		// 设置excel文件名
		String name = "";
		// if("".equals(fileName)){
		// name="详细数据"+ new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		// }else{
		// name = fileName.split("：")[1];
		// }
		excelVo.setFileName(fileName);
		// 标题数组
		// String[] titleArray = tables.get(0);
		// 创建sheet
		SheetVo sheetVo = new SheetVo();
		sheetVo.setSheetNo(1);
		sheetVo.setName("概览数据");
		excelVo.addSheet(sheetVo);
		// 创建单元格
		CellVo cellVoFirst = new CellVo();
		for (int i = 0; i < tablesExcle.size(); i++) {
			String[] tables1 = tablesExcle.get(i);
			// 内容数组
			String[] contentArray = tables1;
			for (int j = 0; j < contentArray.length; j++) {
				cellVoFirst = new CellVo();
				cellVoFirst.setText(contentArray[j]);
				cellVoFirst.setColNo(j);
				cellVoFirst.setRowNo(i + 1);
				// cellVoFirst.setFormat(new WritableCellFormat());

				// 加入样式
				if (i == 0) {
					cellVoFirst.setFormat(wcf4);
				}
				if (i == 1) {
					cellVoFirst.setFormat(wcf1);
				} else {
					if (j == 0) {
						cellVoFirst.setFormat(wcf2);
					} else {
						String testStr = contentArray[j];
						if (testStr != null) {
							String testStrnew = testStr.replace(",", "");
							if (isDecimal(testStrnew)) {
								cellVoFirst.setFormat(wcf3);
							} else {
								cellVoFirst.setFormat(wcf2);
							}
						} else {
							cellVoFirst.setFormat(wcf2);
						}
					}
				}

				sheetVo.addCell(cellVoFirst);
			}
		}
		// 导出excel
		ExcelCreate.createExcelForReport(excelVo, response, character);
		HashMap<String, Object> paraMap = new HashMap<String, Object>();
		paraMap.put("result", name);
		return paraMap;
	}

	private ArrayList<String[]> changeTableToList(String str) {
		String[] trs = getElementsByTag(str, "tr");
		ArrayList<String[]> arrtr = new ArrayList<String[]>();
		for (String tr : trs) {
			String[] tds;
			tds = getElementsByTag(tr, "td");
			if (tds.length == 0) {
				tds = getElementsByTag(tr, "th");
			}
			arrtr.add(tds);
		}
		return arrtr;
	}

	/**
	 * 在给定的元素中搜索指定的元素,返回符合条件的元素数组.对于不同级别的同名元素限制作用,即可以
	 * 搜索元素A中的子元素C.而对于元素B中子元素C则过虑,通过多级限定可以准确定位.
	 * 
	 * @param parentElementString
	 *            String
	 * @param tagName
	 *            String
	 * @return String[]
	 */
	private String[] getElementsByTag(String parentElementString, String tagName) {
		Pattern p = Pattern.compile("<" + tagName + "[^>]*?>(.*?)(</" + tagName
				+ ">)|(/>)");
		Matcher m = p.matcher(parentElementString);
		ArrayList<String> al = new ArrayList<String>();
		while (m.find())
			al.add(m.group(1));
		String[] arr = al.toArray(new String[al.size()]);
		al.clear();
		return arr;
	}

	// 判断是否是数字
	public boolean isDecimal(String str) {
		return Pattern.compile("^\\d+(\\.\\d+)?$").matcher(str).matches();
	}

	@RequestMapping("/isQyHaveDp")
	@ResponseBody
	public Map<String, Object> isQyHaveDp(String qySiteId) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		RegionModel region = new RegionModel();
		region.setQySiteId(qySiteId);
		// 查询楼层下的所有店铺
		List<SiteAllInfo> lowDpList = selectSiteService.getTwiceDp(region);
		if (lowDpList.size() == 0) {
			map.put("isHaveDp", "0");
		} else {
			map.put("isHaveDp", "1");
		}
		return map;
	}
}
